package com.matrix.java.chap_06;

import java.util.Scanner;

/*
    格式化整数
 */
public class Ex6_37 {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.print("输入: ");
        int number = input.nextInt();
        int width = input.nextInt();
        input.close();
        System.out.println(format(number, width));
    }

    private static String format(int number, int width) {
        String formatStr = String.valueOf(number);
        if (getSize(number) < width) {
            for (int i = 0; i < width - getSize(number); i++) {
                formatStr = "0" + formatStr;
            }
        }
        return formatStr;
    }

    private static int getSize(int d) {
        int size = 0;
        do {
            size++;
            d /= 10;
        } while (d != 0);
        return size;
    }
}
